import cv2
import numpy as np

# 读取图像
image = cv2.imread('example.jpg')

# 获取图像的宽度和高度
height, width = image.shape[:2]

# 定义旋转中心、旋转角度和缩放比例
center = (width // 2, height // 2)
angle = 45
scale = 1.0

# 获取旋转矩阵
rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

# 进行旋转
rotated_image = cv2.warpAffine(image, rotation_matrix, (width, height))

# 保存旋转后的图像
cv2.imwrite('rotated_image.jpg', rotated_image)